package com.kuang.controller;


import com.kuang.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/t1")
    public String test1(@RequestParam("username") String name, Model model){

        //接受前端参数
        System.out.println("接收前端的参数为："+name);
        //将返回的结果传递给前端，Model
        model.addAttribute("msg",name);
        //视图跳转
        return "test";
    }

    //前端接收的是一个对象：id name sex
    //http://localhost:8080/springmvc_04_controller_war_exploded/user/t2?name=huang&id=1&sex=男
    @GetMapping("/t2")
    public String test2(User user){
    System.out.println(user);
        return "test";
    }

}
